package com.atguigu.lease.web.admin.config;

import com.atguigu.lease.common.converter.StringToBaseEnumConverter;
import com.atguigu.lease.web.admin.interceptor.AuthenticationInterception;
import com.atguigu.lease.web.admin.properties.AuthPathProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author
 * @version 1.0
 * @description:
 * @date 2024/8/12 16:27
 */
@EnableConfigurationProperties(value = AuthPathProperties.class)
@SpringBootConfiguration
public class MyWebMvcConfig implements WebMvcConfigurer {
    @Autowired
    private StringToBaseEnumConverter stringToBaseEnumConverter;
    @Autowired
    private AuthenticationInterception authenticationInterception;
   @Autowired
    private AuthPathProperties authPathProperties;

//    @Override
//    public void addFormatters(FormatterRegistry registry) {
//        //注册转换器
//        registry.addConverter(stringToItemTypeConverter);
//    }


    @Override
    public void addFormatters(FormatterRegistry registry) {
        //注册转换器工厂
        registry.addConverterFactory(stringToBaseEnumConverter);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterception)
                .addPathPatterns(authPathProperties.getInclude())//配置拦截路径
                .excludePathPatterns(authPathProperties.getExclude());//配置不拦截路径


    }
}
